import { UserApi, UserInfoVo } from '@/api/user'

export const useUserStore = defineStore('user', () => {
  const userInfo = ref<UserInfoVo>()

  function setUserInfo(data?: UserInfoVo) {
    userInfo.value = data
  }

  async function toGetUserInfo() {
    try {
      const res = await UserApi.toGetUserInfo()
      if (res.success) {
        setUserInfo(res.item ?? {})
        return Promise.resolve(res.item)
      }
    } catch (e) {
      console.log(e)
    }
  }

  function logout() {
    //
  }

  return {
    userInfo,
    logout,
    setUserInfo,
    toGetUserInfo,
  }
})
